Skip to content

Refactor MappingElasticsearchConverter #1677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed

Refactor MappingElasticsearchConverter #1677

wants to merge 4 commits into from

Conversation

mp911de
Copy link
Member

@mp911de mp911de commented Feb 1, 2021

  • Add support for SpEL expressions via @Value.
  • Simplify readCollectionOrArray to consider properly nested lists and maps
  • Simplify readMap to allow reading generic maps and entities in maps

This allows adding Document to ElasticsearchSimpleTypes.
Also, update DefaultElasticsearchTypeMapper to report a fallback TypeInformation to properly convert nested maps.

Closes #1676.

@mp911de mp911de linked an issue Feb 1, 2021 that may be closed by this pull request
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 1, 2021
Copy link
Collaborator

@sothawo sothawo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two minor remarks

@@ -67,14 +68,14 @@
* {@link Converter} to write a {@link Point} to {@link Map} using {@code lat/long} properties.
*/
@WritingConverter
public enum PointToMapConverter implements Converter<Point, Map<String, Object>> {
public enum PointToMapConverter implements Converter<Point, Document> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we rename all these converters from MapTo... and ...ToMap into DocumentTo...and ...ToDocument?

Copy link
Member Author

@mp911de mp911de Feb 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Let's do that for the next major version as converters are public classes.

* Extension of {@link SpELExpressionParameterValueProvider} to recursively trigger value conversion on the raw
* resolved SpEL value.
*
* @author Mark Oaluch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @author Mark Oaluch
* @author Mark Paluch

@sothawo
Copy link
Collaborator

sothawo commented Feb 2, 2021

But these changes do not remove the messages on startup:

2021-02-02 07:20:06.515  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.geo.Point as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.515  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoPoint as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.515  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to interface org.springframework.data.elasticsearch.core.geo.GeoJson as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.515  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoJsonPoint as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.516  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoJsonMultiPoint as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.516  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoJsonLineString as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.516  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoJsonMultiLineString as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.516  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoJsonPolygon as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.516  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from class org.springframework.data.elasticsearch.core.geo.GeoJsonMultiPolygon to interface java.util.Map as writing converter although it doesn't convert to a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.516  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoJsonMultiPolygon as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.516  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoJsonGeometryCollection as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.637  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.geo.Point as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.637  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoPoint as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.638  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to interface org.springframework.data.elasticsearch.core.geo.GeoJson as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.638  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoJsonPoint as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.638  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoJsonMultiPoint as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.638  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoJsonLineString as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.638  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoJsonMultiLineString as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.638  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoJsonPolygon as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.638  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from class org.springframework.data.elasticsearch.core.geo.GeoJsonMultiPolygon to interface java.util.Map as writing converter although it doesn't convert to a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.638  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoJsonMultiPolygon as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.
2021-02-02 07:20:06.639  WARN 80774 --- [           main] o.s.data.convert.CustomConversions       : Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoJsonGeometryCollection as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.

@mp911de
Copy link
Member Author

mp911de commented Feb 2, 2021

It seems, that we need to add Map as well as simple type. That change requires a bit more rewrite of the converter.

@mp911de
Copy link
Member Author

mp911de commented Feb 2, 2021

Actually, this change is quite useful as some components in the Template API lookup Collections.singletonMap(…), LinkedHashMap etc. as PersistentEntity which is wrong in the first place.

@sothawo
Copy link
Collaborator

sothawo commented Feb 2, 2021

important is, that the tests still run, we have some places where people read and write generic/dynamic lists, maps and stuff; these known cases are covered by tests, so as long as they don't break

@mp911de
Copy link
Member Author

mp911de commented Feb 2, 2021

I had to update one test as the top-level document now writes a _class attribute. We can discuss whether that makes sense or not.

@mp911de
Copy link
Member Author

mp911de commented Feb 2, 2021

I decided to revert the converters change. They now are returning Map (as previously, so we can drop both commits regarding GeoConverters) as the converter rewrite allows now to consider Map as simple type.

@sothawo
Copy link
Collaborator

sothawo commented Feb 2, 2021

I'll check after work today

Copy link
Collaborator

@sothawo sothawo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one comment about the test change; other wise to merge.

@@ -211,6 +211,7 @@ public void init() {
shotGunAsMap.put("_class", ShotGun.class.getName());

notificationAsMap = Document.create();
notificationAsMap.put("_class", Notification.class.getName());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, that change is not really necessary as line 221 (old) already has this. Although using the class to get the name instead of the string is better.

* Add support for SpEL expressions via @value.
* Simplify readCollectionOrArray to consider properly nested lists and maps
* Simplify readMap to allow reading generic maps and entities in maps.
* Report a fallback TypeInformation in DefaultElasticsearchTypeMapper to properly convert nested maps.

We now no longer rely on isSimpleType when writing Maps. This is the preparation to consider Map as simple type.

Resolves #1676.
See #1675.
Fix PersistenceConstructor of Completion to accept the property type String[].

See #1675.
@mp911de
Copy link
Member Author

mp911de commented Feb 3, 2021

Review comments are addressed, commits are squashed and this one is now ready to be merged.

@sothawo
Copy link
Collaborator

sothawo commented Feb 3, 2021

I have 4 commits that the issue branch is ahead of master, the first changing the pom. I can cherry pick the 3 commits with code changes, but if I do this, how do I finish this PR?

@mp911de
Copy link
Member Author

mp911de commented Feb 4, 2021

See https://github.com/spring-projects/spring-data-build/blob/master/CONTRIBUTING.adoc#commit-messages. Specifically, cherry-pick commits, update the commit message and close this PR/delete the branch. Does that help?

@sothawo sothawo removed the status: waiting-for-triage An issue we've not yet triaged label Feb 4, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 4, 2021
@sothawo
Copy link
Collaborator

sothawo commented Feb 4, 2021

commits cherrypicked into master

@fzyzcjy
Copy link

fzyzcjy commented Mar 31, 2021

Hi, when will we have this released? Thanks!

@sothawo
Copy link
Collaborator

sothawo commented Mar 31, 2021

That's included since Feb 17th (release 4.2.0.M4). 4.2.0.RC1 will be released these days, 4.2.0.GA will robably come mid April

@fzyzcjy
Copy link

fzyzcjy commented Mar 31, 2021

@sothawo Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Align MappingElasticsearchConverter with other Spring Data converters Consider Document as simple type
4 participants